package com.yn.pet.controller.pc.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.yn.common.utils.bean.BeanUtils;
import com.yn.pet.bus.entity.LocationRealtime;
import com.yn.pet.bus.enums.LocationTypeEnum;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class LocationRealtimeResponse {

    //定位ID
    private Long locationId;
    //设备ID
    private Long deviceId;

    //设备昵称
    private String deviceName;

    //imei
    private String imei;


    //经度
    private Double longitude;
    //纬度
    private Double latitude;

    //详细位置
    private String detailedLocation;

    //行走距离
    private Double mileage;

    //速度(km/h)
    private Integer speed;

    //数据状态
    private Integer dataStatus;

    //服务器接收时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date receiveTime;

    //GPS时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date gpsTime;

    //定位类型
    private Integer locationType;

    //定位类型字符串
    private String locationTypeName;

    public static LocationRealtimeResponse transform(LocationRealtime locationRealtime){
        if(locationRealtime == null){
            return null;
        }
        if(locationRealtime.getDataStatus()==2){
            return null;
        }
        LocationRealtimeResponse response = new LocationRealtimeResponse();
        BeanUtils.copyProperties(locationRealtime,response);
        response.setLocationTypeName(LocationTypeEnum.getName(locationRealtime.getLocationType()));
        if(locationRealtime.getReceiveTime() != null){
            response.setGpsTime(locationRealtime.getReceiveTime());
        }else{
            response.setGpsTime(locationRealtime.getGpsTime());
        }
        if(locationRealtime.getMileage()== null){
            response.setMileage(0.0);
        }else{
            response.setMileage(locationRealtime.getMileage());
        }
        if(locationRealtime.getSpeed()>0){
            response.setSpeed(locationRealtime.getSpeed()/10);
        }
        return response;
    }
}
